import router from '@/router'
import store from '@/store'

// 免登录页面
const freeLoginList = ['/', '/login', '/about']

router.beforeEach((to, from, next) => {
    const userInfo = store.getters.userInfo
    if (userInfo) {
        return next()
    }
    store.dispatch('user/getInfo')
        .then(() => {
            next()
        }).catch(() => {
            if (freeLoginList.includes(to.path)) {
                return next()
            }
            next('/login')
        })
})